package com.xy.view.test;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.xy.debug.LogUtils;

/**
 * Created by John on 2016/11/10.
 */

public class CView extends Button {
    public CView(Context context) {
        super(context);
    }

    public CView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        LogUtils.i("Cview - dispatchTouchEvent");
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                LogUtils.i("Cview - dispatchTouchEvent - ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                LogUtils.i("Cview - dispatchTouchEvent - ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.i("Cview - dispatchTouchEvent - ACTION_UP");
                break;
            case MotionEvent.ACTION_CANCEL:
                LogUtils.i("Cview - dispatchTouchEvent - ACTION_CANCEL");
                break;
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        LogUtils.i("Cview - onTouchEvent");
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                LogUtils.i("Cview - onTouchEvent - ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                LogUtils.i("Cview - onTouchEvent - ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                LogUtils.i("Cview - onTouchEvent - ACTION_UP");
                break;
            case MotionEvent.ACTION_CANCEL:
                LogUtils.i("Cview - onTouchEvent - ACTION_CANCEL");
                break;
        }
        //button的super.onTouchEvent默认返回true 普通view 默认返回false由上层处理。
        return super.onTouchEvent(event);
    }
}
